/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fasea.index.filehandler;

import fasea.search.documents.MP3Document;
import fasea.search.documents.Document;
import fasea.search.documents.DefaultDocument;
import fasea.search.documents.RARDocument;
import fasea.search.documents.HTMLDocument;
import fasea.search.documents.RTFDocument;
import fasea.search.documents.ImageDocument;
import fasea.search.documents.WPDDocument;
import fasea.search.documents.FolderDocument;
import fasea.search.documents.PDFDocument;
import fasea.search.documents.XLSDocument;
import fasea.search.documents.DOCDocument;
import fasea.search.documents.TXTDocument;
import fasea.search.documents.AppDocument;
import fasea.search.documents.ZIPDocument;
import fasea.search.documents.PPTDocument;
import fasea.utils.FileUtil;
import java.io.File;
import org.apache.commons.io.FilenameUtils;

/**
 *
 * @author lars-wolfram
 */
public enum DocumentType {

    TXT {

        public FileHandler getFileHandler() {
            return new TXTHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new TXTDocument(document);
        }
    }, PDF {

        public FileHandler getFileHandler() {
            return new PDFHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new PDFDocument(document);
        }
    }, DOC {

        public FileHandler getFileHandler() {
            return new DOCHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new DOCDocument(document);
        }
    }, RTF {

        public FileHandler getFileHandler() {
            return new RTFHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new RTFDocument(document);
        }
    }, WPD {

        public FileHandler getFileHandler() {
            return new WPDHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new WPDDocument(document);
        }
    }, HTML {

        public FileHandler getFileHandler() {
            return new HTMLHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new HTMLDocument(document);
        }
    }, HTM {

        public FileHandler getFileHandler() {
            return new HTMLHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new HTMLDocument(document);
        }
    }, XLS {

        public FileHandler getFileHandler() {
            return new XLSHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new XLSDocument(document);
        }
    }, PPT {

        public FileHandler getFileHandler() {
            return new PPTHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new PPTDocument(document);
        }
    }, MP3 {

        public FileHandler getFileHandler() {
            return new MP3Handler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new MP3Document(document);
        }
    }, JPG {

        public FileHandler getFileHandler() {
            return new ImageHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new ImageDocument(document);
        }
    }, JPEG {

        public FileHandler getFileHandler() {
            return new ImageHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new ImageDocument(document);
        }
    }, GIF {

        public FileHandler getFileHandler() {
            return new ImageHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new ImageDocument(document);
        }
    }, PNG {

        public FileHandler getFileHandler() {
            return new ImageHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new ImageDocument(document);
        }
    }, ZIP {

        public FileHandler getFileHandler() {
            return new ZipHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new ZIPDocument(document);
        }
    }, RAR {

        public FileHandler getFileHandler() {
            return new RARHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new RARDocument(document);
        }
    }, EXE {

        public FileHandler getFileHandler() {
            return new AppHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new AppDocument(document);
        }
    }
    , APP {

        public FileHandler getFileHandler() {
            return new AppHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new AppDocument(document);
        }
    }, COM {

        public FileHandler getFileHandler() {
            return new AppHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new AppDocument(document);
        }
    }, CAP {

        public FileHandler getFileHandler() {
            return new AppHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new AppDocument(document);
        }
    }, MSI {

        public FileHandler getFileHandler() {
            return new AppHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new AppDocument(document);
        }
    }, DEFAULT {

        public FileHandler getFileHandler() {
            return new DefaultHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new DefaultDocument(document);
        }
    }, FOLDER {

        public FileHandler getFileHandler() {
            return new FolderHandler();
        }

        public Document getDocument(org.apache.lucene.document.Document document) {
            return new FolderDocument(document);
        }
    };

    public static DocumentType parse(File file) {
        String extensionUpperCase = FilenameUtils.getExtension(file.getName()).toUpperCase();
        if (FileUtil.isDirectory(file)) {
            return DocumentType.FOLDER;
        } else {
            try {
                return DocumentType.valueOf(extensionUpperCase);
            } catch (IllegalArgumentException ex) {
                return DocumentType.DEFAULT;
            }
        }
    }

    public static DocumentType parse(String fileType) {
            try {
                return DocumentType.valueOf(fileType);
            } catch (IllegalArgumentException ex) {
                return DocumentType.DEFAULT;
            }

    }

    public abstract FileHandler getFileHandler();

    public abstract Document getDocument(org.apache.lucene.document.Document document);
}
